var removeNthFromEnd = function (head, n) {
if (!head) return head;
var len = 0;
var tail = head;
while (tail) {
tail = tail.next;
len++;
}
if (len === n) {
return head.next;
}
len = len - n - 1;
tail = head;
while (len) {
tail = tail.next;
len--;
}
tail.next = tail.next.next;
return head;
};
def remove_nth_from_end(head, n)
p=r=head
n.times{ p=p.next }
return head.next if p==nil
(r=r.next;p=p.next) while p.next!=nil
r.next=r.next.next
head
end